/**
 * 日志级别
 */
export enum LogLevel {
    DEBUG = 0,
    INFO = 1,
    WARN = 2,
    ERROR = 3,
    NONE = 4
}

/**
 * 日志管理类
 */
export class Logger {
    private level: LogLevel = LogLevel.INFO;
    private prefix: string = '[Game]';
    
    constructor(level: LogLevel = LogLevel.INFO, prefix: string = '[Game]') {
        this.level = level;
        this.prefix = prefix;
    }
    
    /**
     * 设置日志级别
     */
    public setLevel(level: LogLevel): void {
        this.level = level;
    }
    
    /**
     * 设置日志前缀
     */
    public setPrefix(prefix: string): void {
        this.prefix = prefix;
    }
    
    /**
     * 输出调试日志
     */
    public debug(...args: any[]): void {
        if (this.level <= LogLevel.DEBUG) {
            console.debug(this.prefix, ...args);
        }
    }
    
    /**
     * 输出信息日志
     */
    public info(...args: any[]): void {
        if (this.level <= LogLevel.INFO) {
            console.info(this.prefix, ...args);
        }
    }
    
    /**
     * 输出警告日志
     */
    public warn(...args: any[]): void {
        if (this.level <= LogLevel.WARN) {
            console.warn(this.prefix, ...args);
        }
    }
    
    /**
     * 输出错误日志
     */
    public error(...args: any[]): void {
        if (this.level <= LogLevel.ERROR) {
            console.error(this.prefix, ...args);
        }
    }
    
    /**
     * 输出分组日志
     */
    public group(label: string): void {
        if (this.level <= LogLevel.DEBUG) {
            console.group(`${this.prefix} ${label}`);
        }
    }
    
    /**
     * 结束分组日志
     */
    public groupEnd(): void {
        if (this.level <= LogLevel.DEBUG) {
            console.groupEnd();
        }
    }
    
    /**
     * 输出表格日志
     */
    public table(data: any, columns?: string[]): void {
        if (this.level <= LogLevel.DEBUG) {
            console.table(data, columns);
        }
    }
    
    /**
     * 输出计时日志
     */
    public time(label: string): void {
        if (this.level <= LogLevel.DEBUG) {
            console.time(`${this.prefix} ${label}`);
        }
    }
    
    /**
     * 结束计时日志
     */
    public timeEnd(label: string): void {
        if (this.level <= LogLevel.DEBUG) {
            console.timeEnd(`${this.prefix} ${label}`);
        }
    }
    
    /**
     * 输出断言日志
     */
    public assert(condition: boolean, ...args: any[]): void {
        if (this.level <= LogLevel.ERROR) {
            console.assert(condition, this.prefix, ...args);
        }
    }
    
    /**
     * 输出堆栈跟踪
     */
    public trace(...args: any[]): void {
        if (this.level <= LogLevel.DEBUG) {
            console.trace(this.prefix, ...args);
        }
    }
} 